const http=require('http');
const url=require('url');
const fs=require('fs');
const zlib=require('zlib');
let server=http.createServer((req,res)=>{
    let {pathname,query}=url.parse(req.url);
    
    res.setHeader('Content-Encoding','gzip')

    let rs=fs.createReadStream(`www${pathname}`);
    let gz=zlib.createGzip();
    rs.pipe(gz).pipe(res);
    rs.on('error',err=>{
        res.writeHead(404);
        res.write('404 not found');
        res.end()
    })
})
server.listen(8080)